﻿using System;
using System.Collections.Generic;

using AnimatingHair.Entity;

namespace AnimatingHair.Auxiliary
{
    class SparseMatrix<T> : IEnumerable<T>
    {
        private Dictionary<long, T> matrix = new Dictionary<long, T>();

        public T this[ HairParticle hp1, HairParticle hp2 ]
        {
            get
            {
                long i = hp1.ID;
                long j = hp2.ID;
                //long index = hp1.ID + (hp2.ID << 32);
                return this[ i, j ];
            }
        }

        public T this[ long i, long j ]
        {
            get
            {
                long index = i + (j << 32);
                return matrix[ index ];
            }

            set
            {
                long index = i + (j << 32);
                matrix[ index ] = value;
            }
        }

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return matrix.Values.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return matrix.Values.GetEnumerator();
        }

        #endregion
    }
}
